﻿using System.Linq;
using DeepEarth.Core;
using DeepEarth.Map.Core.Clustering;
using System.Windows;
using DeepEarth.Core.Utilities;

namespace DeepEarth.Map.Core
{
    public class LabelLayer : GlobalCelLayer
    {
        public LabelLayer() : base()
        {
            this.IsHitTestVisible = false;
        }


        // While the parent scale on each frame, no need to override
        //protected override void SynchronizeOnFrame()
        //{
        //    base.SynchronizeOnFrame();
        //    ApplyInverseScaling(CurrentScale);
        //}

        protected override void ApplyInverseScaling(double scale)
        {
            //this.Children.VisibleElements.OfType<OverlayLabel>().Iter(c => { c.OverlayScaleTransform.ScaleX = 1.0 / scale; c.OverlayScaleTransform.ScaleY = 1.0 / scale; });
            //this.Children.UnboundItems.Where(c => c.Visibility == Visibility.Visible).OfType<OverlayLabel>().Iter(c => { c.OverlayScaleTransform.ScaleX = 1.0 / scale; c.OverlayScaleTransform.ScaleY = 1.0 / scale; });

            foreach (OverlayLabel label in this.Children.OfType<OverlayLabel>().Where(l => l.Visibility == Visibility.Visible))
            //foreach (OverlayLabel label in this.Children.OfType<OverlayLabel>())
            {
                label.OverlayScaleTransform.ScaleX = 1.0 / scale;
                label.OverlayScaleTransform.ScaleY = 1.0 / scale;
            }
        }
    }
}
